// Config example
//
//  <filter>
//    <filter-name>SynonymFilter</filter-name>
//    <filter-class>by.ad.servlet.SynonymFilter</filter-class>
//    <init-param>
//      <param-name>/</param-name>
//      <param-value>/index.xml</param-value>
//    </init-param>
//  </filter>
//  <filter-mapping>
//    <filter-name>SynonymFilter</filter-name>
//    <url-pattern>/*</url-pattern>
//  </filter-mapping>
//
package by.ad.filter;

import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class SynonymFilter
  extends ParametrizedFilter
{
  @Override
  public void doFilter(final ServletRequest req, final ServletResponse resp,
    final FilterChain filterChain)
      throws IOException, ServletException
  {
    if (req instanceof HttpServletRequest) {
      final String uri = ((HttpServletRequest) req).getRequestURI();
      if (params.containsKey(uri)) {
        req.getRequestDispatcher(params.get(uri)).forward(req, resp);
        return;
      }
    }
    
    filterChain.doFilter(req, resp);    
  }
}
